package com.example.accessibilityservice

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View

class DrawView(
    context: Context?,
    attrs: AttributeSet? = null
) :
    View(context, attrs) {
    val mutableList: MutableList<Rect> = ArrayList<Rect>()

    val paint = Paint(Paint.ANTI_ALIAS_FLAG)

    init {
        paint.setColor(Color.BLACK)
        paint.strokeWidth = 5f
        paint.style = Paint.Style.STROKE
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        if (mutableList.isEmpty()) return
        for (rect in mutableList) {
            canvas?.drawRect(rect, paint)
        }
    }

    fun setRectList(list: List<Rect>) {
        mutableList.clear()
        mutableList.addAll(list)
        invalidate()
    }


}